package com.sfx.controller;

import com.sfx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2022-11-13
 * Time: 21:25
 */

@Controller
public class UserController2 {

    //1.属性注入
    @Autowired
//    @Resource//Java提供的注解(JDK提供的)
//    private UserService userService;
//
//    public void doController(){
//        System.out.println("do UserController 2.");
//        System.out.println();
//        userService.doService();
//    }

    //2.setter注入

    private UserService userService;
    @Resource
    public void setUserService(UserService userService) {
        this.userService = userService;
    }
    public void doController(){
        System.out.println("do UserController 2.");
        System.out.println();
        userService.doService();
    }

    //3.构造方法注入
    /**
     * Resource注解只能使用属性注入和Setter注入  不能使用构造方法的注入
     */

//    private UserService userService;
//    //@Resource 不支持构造方法注入
//    public UserController2(UserService userService) {
//        this.userService = userService;
//    }
//    public void doController(){
//        System.out.println("do UserController 2.");
//        System.out.println();
//        userService.doService();
//    }
}
